<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
<%@taglib prefix="s" uri="strutsTags"%>
<%@taglib prefix="ty" uri="/wyzzTags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<head>
	<base href="<%=basePath%>">
	<title>员工薪资配置</title>
	<link href="resource/css/style.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="resource/js/hrm/compensation.js"></script>
	<script type='text/javascript' src='dwr/interface/DWRforAcctItemDef.js'></script>
	<script type='text/javascript'
		src='dwr/interface/UpdateSalaryConfigBatch.js'></script>
</head>
<body onload="HRMCommon.check_order();">
	<s:component template="bodyhead">
		<s:param name="pagetitle" value="'员工薪资配置'" />
	</s:component>
	<span class="errorMessage" id="errMsg"></span>
	<s:form id="searchSalary" name="searchSalary" action="searchSalary"
		namespace="/compensation" method="post">
		<s:hidden id="actionErrorS" name="actionErrorS"></s:hidden>
		<table width="100%" class="formtable">
			<tr>
				<td>
					<s:hidden id="id" name="detailid" />
					<s:hidden id="order" name="page.order" />
					<s:hidden id="page.currentPage" name="page.currentPage" />
					<input type="hidden" id="operate" name="page.operate" />
					<table width="100%">
						<tr>
							<s:textfield label="员工" id="employee" name="emp.empName"
								size="16" maxlength="64" />
							<td align="right">
								组织单元:
							</td>
							<td>
								<s:orgselector id="orgselector1"
									name="emp.empDeptNo.departmentName"
									hiddenFieldName="emp.empDeptNo.id" isShowDisable="show" />
							</td>
							<s:select label="工作地区" id="empLocationNo"
								name="emp.empLocationNo.id" list="location" listKey="id"
								listValue="locationName" multiple="false" headerKey=""
								headerValue="请选择" />
							<s:select label="用工形式" id="empType" name="emp.empType.id"
								list="emptype" listKey="id" listValue="emptypeName"
								multiple="false" headerKey="" headerValue="请选择" />
						</tr>
						<tr>
							<s:select label="薪资级别" list="jobgradeList" listKey="id"
								listValue="jobGradeName" name="emp.config.escJobgrade.id"
								emptyOption="true" cssStyle="width:116px;" />
							<s:select label="薪资帐套" list="acctList" listKey="id"
								listValue="esavEsac.esacName" name="emp.config.escEsavId.id"
								emptyOption="true" cssStyle="width:116px;" />
							<s:select label="成本中心" name="emp.config.escCostCenter"
								list="costCenterList" multiple="false" emptyOption="true" />
							<ty:auth auths="201">
								<s:select label="员工状态" id="empStatus" name="emp.empStatus"
									list="empStatus" listKey="id.statusconfNo"
									listValue="statusconfDesc" multiple="false" emptyOption="false"
									value="emp.empStatus" size="1" />
							</ty:auth>
						</tr>
					</table>
				</td>
				<td align="center">
					<input title="[Alt+F]" accesskey="F" id="submit_button"
						class="button" type="submit" value="查询">
					<input title="[Alt+C]" accesskey="C" class="button" type="button"
						value="重置" onClick="window.location='searchSalary.action';">
				</td>
			</tr>
		</table>

		<!-- 操作 -->
		<div class="operatediv">
			<span class="operatedivleft"> <input type="hidden"
					name="searchOrExport" id="searchOrExport" /> <ty:auth auths="201">
					<input class="button" type="button" value="批量修改"
						onclick="return updateBatch()" />
				</ty:auth> <ty:auth auths="201,3 or 201,2">
					<input class="button" type="button" value="数据导入"
						onclick="initDivImmUpload('IEmpSalaryConfig');" />
					<input class="button" type="button" value="数据导出" id="btnOutput"
						onClick="HRMCommon.export_check('export');" />
				</ty:auth> </span>
			<span class="operatedivright">本次查询共得到<s:property
					value="page.totalRows" />条薪资配置记录</span>
		</div>

		<table id="compaplantable" cellpadding="0" cellspacing="0"
			width="100%" border="0" class="gridtableList">
			<tr>
				<th align="center" width="3%">
					<input id="checkboxforall" name='checkboxforall' class="checkbox"
						type="checkbox"
						onclick="HRMCommon.checkAllByName('changIds','checkboxforall');"
						value="全选">
				</th>
				<th>
					<a href="#" onclick="HRMCommon.order_submit('empDistinctNo');">员工编号</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='empDistinctNo_img'>
				</th>
				<th>
					<a href="#" onclick="HRMCommon.order_submit('empName');">姓名</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='empName_img'>
				</th>
				<th>
					<a href="#"
						onclick="HRMCommon.order_submit('empDeptNo.departmentName');">部门</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='empDeptNo.departmentName_img'>
				</th>
				<th>
					<a href="#"
						onclick="HRMCommon.order_submit('empType.emptypeName');">用工形式</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='empType.emptypeName_img'>
				</th>
				<th>
					<a href="#" onclick="HRMCommon.order_submit('empStatus');">状态</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='empStatus_img'>
				</th>
				<th>
					<a href="#"
						onclick="HRMCommon.order_submit('escJobgrade.jobGradeName');">薪资级别</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='escJobgrade.jobGradeName_img'>
				</th>
				<th>
					基本工资
				</th>
				<th>
					税前收入
				</th>
				<th>
					<a href="#" onclick="HRMCommon.order_submit('esavEsac.esacName');">薪资帐套</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='esavEsac.esacName_img'>
				</th>
				<th>
					<a href="#"
						onclick="HRMCommon.order_submit('config.escLastChangeTime');">最后修改</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='config.escLastChangeTime_img'>
				</th>
				<ty:auth auths="201">
					<th>
						操作
					</th>
				</ty:auth>
			</tr>
			<s:if test="!employeeList.isEmpty()">
				<s:iterator value="employeeList" status="index">
					<input type="hidden" id="acctIds" name="acctIds"
						value="<s:property value='config.escEsavId.id'/>" />
					<tr>
						<s:if test="config.escJobgrade!=null">
							<td align="center" width="3%">
								<input id="changIds" name='changIds' type="checkbox"
									class="checkbox" value="<s:property value='id'/>" />
							</td>
							<td align="left" nowrap="nowrap">
								<a style="cursor:hand;"
									onclick="HRMCp.viewDetail('<s:property value='id'/>');"
									class="listViewTdLinkS1"><s:property value="empDistinctNo" />
								</a>
							</td>
						</s:if>
						<s:else>
							<td />
							<td align="left" nowrap="nowrap">
								<s:property value="empDistinctNo" />
							</td>
						</s:else>

						<td id="name<s:property value='%{#index.count}'/>" align="center">
							<s:property value="empName" />
						</td>
						<td align="center">
							<s:property value="empDeptNo.departmentName" />
						</td>
						<td align="center">
							<s:property value="empType.emptypeName" />
						</td>
						<td align="center">
							<s:if test="empStatus ==0">离职</s:if>
							<s:else>在职</s:else>
						</td>
						<td id="td_jg<s:property value='%{#index.count}'/>" align="center">
							<s:property value="getJobgradeName(config.escJobgrade.id)" />
						</td>
						<td id="td_bs<s:property value='%{#index.count}'/>" align="right"
							nowrap="nowrap">
							<s:property value="config.showColumn1" />
						</td>
						<td id="td_gross<s:property value='%{#index.count}'/>"
							align="right" nowrap="nowrap">
							<s:property value="config.showColumn8" />
						</td>
						<td id="td_esac<s:property value='%{#index.count}'/>"
							align="center">
							<s:property value="config.escEsavId.esavEsac.esacName" />
						</td>
						<td id="td_date<s:property value='%{#index.count}'/>"
							align="center" nowrap="nowrap">
							<s:date name="config.escLastChangeTime" format="yyyy-MM-dd" />
						</td>

						<ty:auth auths="201">
							<s:if test="config.escJobgrade!=null">
								<td align="center" nowrap="nowrap">
									<img onclick="updateSalary('<s:property value='config.id'/>')"
										alt="修改" title="修改" style="CURSOR: pointer"
										src="resource/images/edit.gif" border="0" />
									<img
										onclick="deleteSalaryConfig('<s:property value='id'/>','<s:property value='#index.count'/>')"
										alt="删除" title="删除" style="CURSOR: pointer"
										src="resource/images/delete.gif" border="0" />
								</td>
							</s:if>
							<s:else>
								<td align="center" nowrap="nowrap">
									<img onclick="createSalaryconf('<s:property value='id'/>')"
										alt="创建薪资" title="创建薪资" style="CURSOR: pointer" border="0"
										src="resource/images/CreateProject.gif" />
								</td>
							</s:else>
						</ty:auth>
					</tr>
				</s:iterator>
			</s:if>
			<s:else>
				<tr>
					<!-- 不存在符合条件的员工薪资配置！ -->
					<td align="center" colspan="12">
						不存在符合条件的员工薪资配置！
					</td>
				</tr>
			</s:else>
		</table>
		<s:pager end="page.end" pageNo="page.currentPage"
			totalRows="page.totalRows" totalPages="page.totalPages"
			formId="searchSalary" start="page.start" />

		<div id="dlgUpdateBatchDiv" class="prompt_div_inline" title="批量修改薪资配置"
			style="width: 280; display: none;">
			<div id="change_stutus_error" class="prompt_div_err"></div>
			<input type="hidden" name="empIds" id="empIds" />
			<table width="100%" class="prompt_div_body">
				<tr>
					<td>
						选择薪资项目:
					</td>
					<td>
						<select id="acctItemSelect" name="acctItemSelect"></select>
					</td>
				</tr>
				<tr>
					<td>
						对应项目数值:
					</td>
					<td>
						<input type="text" id="batchSalary" name="batchSalary"
							onkeydown="HRMCommon.checkOnKeyDownFloat(event,this)"
							onblur="HRMCommon.checkFloatAndFormat(this,2,true);" />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<font color="red">备注：只允许修改薪资配置中的固定项。</font>
					</td>
				</tr>
				<tr>
					<td colspan="2" class="prompt_div_bottom">
						<input class="button" type="button" name="batchButton" value="确定"
							onclick="updateSubmit()" />
						<input class="button" type="button" name="closeButton" value="取消"
							onclick="HRMCommon.closeDialog('dlgUpdateBatchDiv')" />
					</td>
				</tr>
			</table>
		</div>
	</s:form>

	<script type="text/javascript" language="javascript">
function updateBatch() {
	var ids = HRMCommon.getCheckboxByName('changIds', true); // 没有单引号
	if(ids.length == 0){
		alert("请至少选择一个员工！");
		return false;
	}

	document.getElementById('empIds').value = ids;

	var acctValue = document.getElementsByName('acctIds');
	var checkBoxName = document.getElementsByName('changIds');
	var acctSel = null;
	for(var i=0;i<acctValue.length;i++) {
		if (!checkBoxName[i].checked) continue;
		if (acctSel == null) {
			acctSel = acctValue[i].value;
		}

		if(acctValue[i].value != acctSel) {
			alert('不能同时批量修改多个帐套员工的薪资！');
			return false;
		}
	}
	
	DWRforAcctItemDef.getAcctItemsById(acctSel, getItemCallBack);
	function getItemCallBack(msg){
		if(msg == null){
			errMsg("errMsg", "数据异常，请刷新后再试！");
			return;
		}
		var index = 0;
		for(var i=0;i<msg.length;i++) {
			if(msg[i].esaiDataIsCalc == 0){
				document.getElementById('acctItemSelect').options[index++]=new Option(msg[i].esaiEsdd.esddName,msg[i].id,true,true);
			}
		}
		HRMCommon.openDialog('dlgUpdateBatchDiv');
	}
}

function updateSubmit(){
	var empIds = document.getElementById('empIds').value;
	var itemId = document.getElementById('acctItemSelect').value;
	var salaryValue = document.getElementById('batchSalary').value;
	
	UpdateSalaryConfigBatch.updateConfigBatch(empIds, itemId, salaryValue, updateCallBack);
	
	function updateCallBack(msg) {
		try{
			var retcode = HRMCommon.comboMsgHandler(msg);
			if(retcode == 'SUCC') {
		 		HRMCommon.closeDialog('dlgUpdateBatchDiv');
		 	 	document.getElementById("actionErrorS").value = msg;
				document.forms[0].submit();
			}
		}catch(e){alert(e);}
	}
}

//创建salaryconf
function createSalaryconf(id) {
	  var editaction = "compensation/addSalaryConfigInit.action?id=" + id;
	  document.searchSalary.action = editaction;
	  document.searchSalary.submit();
}

//删除 salaryconf
function deleteSalaryConfig(var1, index) {
	  var empname = document.getElementById('name' + index).innerHTML;
	  if (confirm("您确定要删除" + empname.trim() + "的薪资配置吗？")) {
		    var url = "compensation/deleteSalaryConfig.action?id=" + var1;
		    document.searchSalary.action = url;
		    document.searchSalary.submit();
	  }
}
   
function updateSalary(id) {
	var url='compensation/updateSalaryConfigInit.action?id='+id+"&paramString="+"updateSalaryConf";
	var fm = document.getElementById('searchSalary');
	fm.action=url;
	fm.submit();
}

HRMCommon.initDialog('dlgUpdateBatchDiv');	
</script>
	<jsp:include flush="true" page="../io/div_upload.jsp"></jsp:include>
</body>

